﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Benefit.Models.ServerData
{
    /// <summary>
    /// 平仓明细
    /// </summary>
    public class T_ClosePositionDetail_History
    {
        /// <summary>
        /// 编号
        /// </summary>
        public int Id { get; set; }
        /// <summary>
        /// 账户编号
        /// </summary>
        public int AccountId { get; set; }
        /// <summary>
        /// 合约编号
        /// </summary>
        public string InstrumentId { get; set; }
        /// <summary>
        /// 平仓时间
        /// </summary>
        public int CloseDate { get; set; }
        /// <summary>
        /// 开仓时间
        /// </summary>
        public int OpenDate { get; set; }
        /// <summary>
        /// 交易所代码
        /// </summary>
        public string ExchangeId { get; set; }
        /// <summary>
        /// 品种代码
        /// </summary>
        public string ProductId { get; set; }
        /// <summary>
        /// 交割时间
        /// </summary>
        public string DeliveryDate { get; set; }
        /// <summary>
        /// 方向
        /// </summary>
        public string Direction { get; set; }
        /// <summary>
        /// 手数
        /// </summary>
        public int Volume { get; set; }
        /// <summary>
        /// 开仓价
        /// </summary>
        public double OpenPrice { get; set; }
        /// <summary>
        /// 昨结算价
        /// </summary>
        public double YesterdaySettlement { get; set; }
        /// <summary>
        /// 平仓价
        /// </summary>
        public double TradePrice { get; set; }
        /// <summary>
        /// 平仓盈亏
        /// </summary>
        public double CloseProfit { get; set; }
        /// <summary>
        /// 平仓盈亏(逐笔)
        /// </summary>
        public double CloseProfit2 { get; set; }
        /// <summary>
        /// 结算编号
        /// </summary>
        public int SettlementId { get; set; }
        /// <summary>
        /// 交易日
        /// </summary>
        public string TradingDay { get; set; }


        ///// <summary>
        ///// 查询结算后的平仓明细
        ///// </summary>
        ///// <param name="accountid"></param>
        ///// <param name="pdate"></param>
        ///// <returns></returns>
        //private System.Collections.Generic.List<T_ClosePositionDetail_History> GetInfo(string pdate)
        //{
        //    List<T_ClosePositionDetail_History> ios = new List<T_ClosePositionDetail_History>();
        //    T_Settle_History tsh = new T_Settle_History();
        //    int settlementid = tsh.GetDayMaxSettlementInfoId(pdate);
        //    if (settlementid != -1)
        //    {
        //        ios = GetClosePositionDetailHistoryInfo(settlementid, pdate);
        //    }
        //    return ios;
        //}

        ///// <summary>
        ///// 查询某天最大结算编号的出入金记录
        ///// </summary>
        ///// <param name="settlementid">结算编号</param>
        ///// <param name="pdate">日期</param>
        ///// <returns></returns>
        //private System.Collections.Generic.List<T_ClosePositionDetail_History> GetClosePositionDetailHistoryInfo(int settlementid, string pdate)
        //{
        //    System.Collections.Generic.List<T_ClosePositionDetail_History> ios = new System.Collections.Generic.List<T_ClosePositionDetail_History>();
        //    string sql = "select * from T_ClosePositionDetail_History where SettlementId='" + settlementid + "' and tradingday='" + pdate + "'";
        //    OracleDataReader sdr = Common.ADO.Tools.OracleHelper.ExecuteReader(sql);
        //    while (sdr.Read())
        //    {
        //        if (Convert.ToInt32(sdr["Volume"]) > 0)
        //        {
        //            T_ClosePositionDetail_History s = null;
        //            s = new T_ClosePositionDetail_History();
        //            s.AccountId = Convert.ToInt32(sdr["AccountId"]);
        //            s.CloseDate = Convert.ToInt32(sdr["CloseDate"]);
        //            s.CloseProfit = Convert.ToDouble(sdr["CloseProfit"]);
        //            s.CloseProfit2 = Convert.ToDouble(sdr["CloseProfit2"]);
        //            s.DeliveryDate = sdr["DeliveryDate"].ToString();
        //            s.Direction = Convert.ToString(sdr["Direction"]);
        //            s.ExchangeId = Convert.ToString(sdr["ExchangeId"]);
        //            s.Id = Convert.ToInt32(sdr["Id"]);
        //            s.InstrumentId = Convert.ToString(sdr["InstrumentId"]);
        //            s.OpenDate = Convert.ToInt32(sdr["OpenDate"]);
        //            s.OpenPrice = Convert.ToDouble(sdr["OpenPrice"]);
        //            s.ProductId = Convert.ToString(sdr["ProductId"]);
        //            s.SettlementId = Convert.ToInt32(sdr["SettlementId"]);
        //            s.TradePrice = Convert.ToDouble(sdr["TradePrice"]);
        //            s.TradingDay = Convert.ToString(sdr["TradingDay"]);
        //            s.Volume = Convert.ToInt32(sdr["Volume"]);
        //            s.YesterdaySettlement = Convert.ToDouble(sdr["YesterdaySettlement"]);
        //            ios.Add(s);
        //        }
        //    }
        //    sdr.Close();
        //    return ios;
        //}

        ///// <summary>
        ///// 每天都需要执行的把Server中的数据导入到分析系统中的方法
        ///// </summary>
        ///// <param name="pdate">日期</param>
        //public void CopyServerClosePositionDetailHistoryDataIntoBenefit(string pdate, DB.DBManager db)
        //{
        //    Data.ServerData.T_ClosePositionDetail_History h = new Data.ServerData.T_ClosePositionDetail_History();
        //    List<Data.ServerData.T_ClosePositionDetail_History> historys = h.GetInfo(pdate);
        //    foreach (Data.ServerData.T_ClosePositionDetail_History ha in historys)
        //    {
        //        db.ClosePositionDetail.Add(ha);
        //    }
        //    db.SaveChanges();
        //}
        ///// <summary>
        ///// 删除某日的所有出入金记录
        ///// </summary>
        ///// <param name="pdate"></param>
        //public void DeleteDayClosePositionDetailHistoryFromBenefit(string pdate, DB.DBManager db)
        //{
        //    var historys = from t in db.ClosePositionDetail where t.TradingDay.Equals(pdate) select t;
        //    foreach (Data.ServerData.T_ClosePositionDetail_History ha in historys)
        //    {
        //        db.ClosePositionDetail.Remove(ha);
        //    }
        //    db.SaveChanges();
        //}

    }
}